package rule02;

/**
 * @author ChangLiang
 * @date 2020/3/16
 */
public class PersonV3 {

    /**
     * 必填
     */
    private String firstName;

    /**
     * 必填
     */
    private String lastName;

    /**
     * 选填
     */
    private String city;

    /**
     * 选填
     */
    private String address;

    /**
     * 选填
     */
    private boolean isMale;

    public static class Builder{
        private final String firstName;
        private final String lastName;
        private String city;
        private String address;
        private boolean isMale;

        public Builder(String firstName, String lastName) {
            this.firstName = firstName;
            this.lastName = lastName;
        }

        public Builder city(String city) {
            this.city = city;
            return this;
        }

        public Builder address(String address) {
            this.address = address;
            return this;
        }

        public Builder isMale(boolean isMale) {
            this.isMale = isMale;
            return this;
        }

        public PersonV3 build() {
            return new PersonV3(this);
        }
    }

    /**
     * 这里设置为private 只能通过Builder build出来
     * @param builder
     */
    private PersonV3(Builder builder) {
        this.firstName = builder.firstName;
        this.lastName = builder.lastName;
        this.city = builder.city;
        this.address = builder.address;
        this.isMale = builder.isMale;
        // 统一执行参数检查 如果不合法 抛出exception

    }
}
